#include <iostream>
#include <stack>
using namespace std;
typedef unsigned long long ull;
int t;
const int N = 1e6 + 10;
int top;
ull stk[N];
int main()
{
    cin >> t;
    while(t--)
    {
        int n;
        cin >> n;
        // 清空栈
        top = 0;
        while(n--)
        {
            string op; cin >> op;
            if(op == "push")
            {
                ull x;
                cin >> x;
                stk[++top] = x;
            }else if(op == "pop")
            {
                if(top == 0) cout << "Empty" << endl;
                else top--;
            }else if(op == "query")
            {
                if(top == 0) cout << "Anguei!" << endl;
                else cout << stk[top] << endl;
            }else
            {
                cout << top << endl;
            }
        }
    }
    return 0;
}